package com.omronservice.web.scheduled.service;

import com.omronservice.utils.OkHttpUtil;
import com.omronservice.vo.RequestMessage;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: MesService
 * @Author: lfr
 * @CreateDate: 2019/09/12$ 15:18$
 * @UpdateUser: lfr
 * @UpdateDate: 2019/09/12$ 15:18$
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Service
public class MesService {

    public void AreYouThere(){
        Map map=new HashMap();
        //map.put("requestMessage","{   \"Header\": {       \"MESSAGENAME\": \"MES.AREYOUTHERE\",       \"TRANSACTIONID\": \"20140807095523941368\",       \"ORGRRN\": \"12\",       \"ORGNAME\": \"Cell\",       \"USERNAME\": \"EIS\"     },     \"Body\": {       \"name\": \"jwhan\",       \"age\": \"29\"     } }");
        map.put("requestMessage", RequestMessage.requestMessageUtil("MES.AREYOUTHERE","20140807095523941368"));
        map.put("senderId","MESAutoSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }
    /**
     * Online/Offline切换 以及设备状态上报
     */
    public void equipmentStateReport(){
        Map map=new HashMap();
        map.put("requestMessage","{   \"Header\": {       \"MESSAGENAME\": \"MES.EQUIPMENTSTATEREPORT\",       \"TRANSACTIONID\": \"20140807095523941368\",       \"ORGRRN\": \"378341\",       \"ORGNAME\": \"Cell\",       \"USERNAME\": \"SWTS\"     },     \"Body\": {       \"ACTIONTYPE\": \"STATE\",       \"EQUIPMENTID\": \"HZY-EQP1\" ,       \"COMCLASS\": \"run\",       \"STATE\": \"run\"    } }");

        // map.put("requestMessage", RequestMessage.RequestMessageUtil("MES.EQUIPMENTSTATEREPORT","20140807095523941368"));
        map.put("senderId","MESAutoSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }
    /**
     * 设备端口状态切换
     */
    public void equipmentPortReport(){
        Map map=new HashMap();

        map.put("requestMessage","{\n" +
                "    \"Header\":{\n" +
                "        \"MESSAGENAME\":\"MES.EQUIPMENTPORTREPORT\",\n" +
                "        \"TRANSACTIONID\":\"Pb1n7P7MXaTmPkCYMcoad1\",\n" +
                "        \"ORGRRN\":\"378341\",\n" +
                "        \"ORGNAME\":\"GZSL02\",\n" +
                "        \"USERNAME\":\"EAP\"\n" +
                "    },\n" +
                "    \"Body\":{\n" +
                "        \"EQUIPMENTID\":\"\",\n" +
                "        \"PORTLIST\":[\n" +
                "            {\n" +
                "                \"PORTID\":\"C01\",\n" +
                "                \"PORTSTATE\":\"AVL\"\n" +
                "            },\n" +
                "{\n" +
                "                \"PORTID\":\"C02\",\n" +
                "                \"PORTSTATE\":\"AVL\"\n" +
                "            }\n" +
                "        ]\n" +
                "    }\n" +
                "}");
        map.put("senderId","MESAutoSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }
    /**
     * BC - MES 时间同步
     */
    public void dateTimeSetRequest(){
        Map map=new HashMap();

        map.put("requestMessage","{\n" +
                "    \"Header\": {\n" +
                "      \"MESSAGENAME\": \"MES.DATETIMESETREQUEST\",\n" +
                "      \"TRANSACTIONID\": \"20140807095523941368\",\n" +
                "      \"ORGRRN\": \"12\",\n" +
                "      \"ORGNAME\": \"Cell\",\n" +
                "      \"USERNAME\": \"EIS\"\n" +
                "    },\n" +
                "    \"Body\": { \"EQUIPMENTID\": \"ABCDE\" }\n" +
                "  }\n" +
                "}");
        map.put("senderId","MESAutoSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }
    /**
     * Loader口请求载具时上报
     */
    public void loadRequest(){
        Map map=new HashMap();

        map.put("requestMessage","{\n" +
                "   \"Header\": {\n" +
                "      \"MESSAGENAME\": \"MES.LOADREQUEST\",\n" +
                "      \"TRANSACTIONID\": \"20140807095523941368\",\n" +
                "      \"ORGRRN\": \"378341\",\n" +
                "      \"ORGNAME\": \"Array\",\n" +
                "      \"USERNAME\": \"admin\"\n" +
                "    },\n" +
                "    \"Body\": {\n" +
                "      \"ACTIONTYPE\": \"ABCDE\",\n" +
                "      \"EQUIPMENTID\": \"HZY-EQP1\",\n" +
                "      \"PORTID\": \"C01\",\n" +
                "      \"PORTREQUESTTYPE\": \"\"\n" +
                "    }\n" +
                "}");
        map.put("senderId","MESAutoSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }
    /**
     * Loader口载具加载完成报告
     */
    public void loadComplete(){
        Map map=new HashMap();

        map.put("requestMessage","{\n" +
                "   \"Header\": {\n" +
                "      \"MESSAGENAME\": \"MES.LOADCOMPLETE\",\n" +
                "      \"TRANSACTIONID\": \"20140807095523941368\",\n" +
                "      \"ORGRRN\": \"378341\",\n" +
                "      \"ORGNAME\": \"Array\",\n" +
                "      \"USERNAME\": \"EIS\"\n" +
                "    },\n" +
                "    \"Body\": {\n" +
                "      \"ACTIONTYPE\": \"\",\n" +
                "      \"EQUIPMENTID\": \"HZY-EQP1\",\n" +
                "      \"PORTID\": \"C01\",\n" +
                "      \"DURABLEID\": \"RTD-001\",\n" +
                "      \"PORTREQUESTTYPE\": \"PRO\"\n" +
                "    }\n" +
                "}");
        map.put("senderId","MaxwellSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }
    /**
     * Loader口请求载具信息时上报
     */
    public void lotInfoDownload(){
        Map map=new HashMap();

        map.put("requestMessage","{\n" +
                "  \"Header\": {\n" +
                "      \"MESSAGENAME\": \"MES.LOTINFODOWNLOAD\",\n" +
                "      \"TRANSACTIONID\": \"20140807095523941368\",\n" +
                "      \"ORGRRN\": \"378341\",\n" +
                "      \"ORGNAME\": \"Array\",\n" +
                "      \"USERNAME\": \"EIS\"\n" +
                "    },\n" +
                "    \"Body\": {\n" +
                "      \"ACTIONTYPE\": \"INSPECTION\",\n" +
                "      \"EQUIPMENTID\": \"HZY-EQP1\",\n" +
                "      \"PORTID\": \"C01\",\n" +
                "      \"DURABLEID\": \"LCL-004\"\n" +
                "    }\n" +
                "}");
        map.put("senderId","MaxwellSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }
    /**
     * Loader口请求退载具时上报
     */
    public void unloadRequest(){
        Map map=new HashMap();

        map.put("requestMessage","{\n" +
                "\"Header\":{\n" +
                "\"MESSAGENAME\":\"MES.UNLOADREQUEST\",\n" +
                "\"TRANSACTIONID\":\"20140807095523941368\",\n" +
                "\"ORGRRN\":\"378341\",\n" +
                "\"ORGNAME\":\"GZSL02\",\n" +
                "\"USERNAME\":\"EAP\"\n" +
                "},\n" +
                "\"Body\":{\n" +
                "\"EQUIPMENTID\":\"2019091601\",\n" +
                "\"PORTID\":\"2019091601\",\n" +
                "\"DURABLEID\":\"94131703\",\n" +
                "\"STEPNAME\":\"111\",\n" +
                "\"NEXTSTEPNAME\":\"123\",\n" +
                "\"COMPONENTLIST\":[\n" +
                "{\n" +
                "\"COMPONENTID\":\"TEST-L-9410\",\n" +
                "\"POSITION\":\"1\"\n" +
                "}\n" +
                "]\n" +
                "}\n" +
                "}");
        map.put("senderId","MaxwellSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }
    /**
     * Loader口卸载载具完成报告
     */
    public void unloadComplete(){
        Map map=new HashMap();

        map.put("requestMessage","{\n" +
                "   \"Header\": {\n" +
                "      \"MESSAGENAME\": \"MES.UNLOADCOMPLETE\",\n" +
                "      \"TRANSACTIONID\": \"20140807095523941368\",\n" +
                "      \"ORGRRN\": \"378341\",\n" +
                "      \"ORGNAME\": \"Array\",\n" +
                "      \"USERNAME\": \"EIS\"\n" +
                "    },\n" +
                "    \"Body\": {\n" +
                "      \"ACTIONTYPE\": \"\",\n" +
                "      \"EQUIPMENTID\": \"TESTEQPLCM23\",\n" +
                "      \"PORTID\": \"C01\",\n" +
                "      \"DURABLEID\": \"RTD-001\",\n" +
                "      \"PORTREQUESTTYPE\": \"PRO\"\n" +
                "    }\n" +
                "}");
        map.put("senderId","MaxwellSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }
    /**
     * 批次进站
     */
    public void lotTrackIn(){
        Map map=new HashMap();

        map.put("requestMessage","{\n" +
                "  \"Header\": {\n" +
                "      \"MESSAGENAME\": \"MES.LOTTRACKIN\",\n" +
                "      \"TRANSACTIONID\": \"20140807095523941368\",\n" +
                "      \"ORGRRN\": \"378341\",\n" +
                "      \"ORGNAME\": \"Array\",\n" +
                "      \"USERNAME\": \"EIS\"\n" +
                "    },\n" +
                "    \"Body\": {\n" +
                "      \"EQUIPMENTID\": \"HZY-EQP1\",\n" +
                "      \"PORTID\": \"C01\",\n" +
                "  \"LOTID\": \"_190900011\",\n" +
                "  \"STEPNAME\": \"1000\",\n" +
                "      \"DURABLEID\": \"RTD-020\"\n" +
                "    }\n" +
                "}");
        map.put("senderId","MaxwellSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }

    /**
     * 硅片报废
     */
    public void componentScrap(){
        Map map=new HashMap();

        map.put("requestMessage","{   \"Header\": {       \"MESSAGENAME\": \"MES.COMPONENTSCRAP\",       \"TRANSACTIONID\": \"20140807095523941368\",       \"ORGRRN\": \"12\",       \"ORGNAME\": \"Cell\",       \"USERNAME\": \"EIS\"     },     \"Body\": {       \"ACTIONTYPE\": \"\",       \"EQUIPMENTID\": \"HZY-EQP1\" ,       \"UNITID\": \"\" ,       \"PLANTID\": \"\" ,       \"POSITION\": \"\" ,       \"LOTID\": \"\"  ,       \"STEPNAME\": \"\" ,       \"ACTIONCODE\": \"\" ,       \"ACTIONCOMMENT\": \"\" ,       \"COMPONENTLIST\":[\n" +
                "            {\n" +
                "                \"COMPONENTID\":\"TEST-001\",\n" +
                "\"COMPONENT\":\"\"\n" +
                "            }\n" +
                "        ]    } }");

        map.put("senderId","MaxwellSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }

    /**
     * 物料Kitting (加载到设备后设备上录入)
     */
    public void materialKitting(){
        Map map=new HashMap();
        map.put("requestMessage","{\n" +
                "\"Header\": {\n" +
                "\"MESSAGENAME\": \"MES.MATERIALKITTING\",\n" +
                "\"TRANSACTIONID\": \"\",\n" +
                "\"ORGRRN\": \"378341\",\n" +
                "\"ORGNAME\": \"Array\",\n" +
                "\"USERNAME\": \"admin\"\n" +
                "},\n" +
                "\"Body\": {\n" +
                "\"EQUIPMENTID\": \"MATEN-01-T3\",\n" +
                "\"MLOTLIST\": [\n" +
                "{\n" +
                "\"MLOTID\": \"mlot10\",\n" +
                "\"MATERIALNAME\": \"MM002\"\n" +
                "}\n" +
                "]\n" +
                "}\n" +
                "}".trim());


        map.put("senderId","MaxwellSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }


    /**
     * 设备加工信息,设备参数上报（未测试）
     */
    public void processData(){
        Map map=new HashMap();
        map.put("requestMessage","{\n" +
                "\"Header\": {\n" +
                "\"MESSAGENAME\": \"MES.MATERIALKITTING\",\n" +
                "\"TRANSACTIONID\": \"\",\n" +
                "\"ORGRRN\": \"378341\",\n" +
                "\"ORGNAME\": \"Array\",\n" +
                "\"USERNAME\": \"admin\"\n" +
                "},\n" +
                "\"Body\": {\n" +
                "\"EQUIPMENTID\": \"MATEN-01-T3\",\n" +
                "\"MLOTLIST\": [\n" +
                "{\n" +
                "\"MLOTID\": \"mlot10\",\n" +
                "\"MATERIALNAME\": \"MM002\"\n" +
                "}\n" +
                "]\n" +
                "}\n" +
                "}".trim());


        map.put("senderId","MaxwellSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }

    /**
     * 设备自己生成虚拟ID信息时上报
     */
    public void createLot(){
        Map map=new HashMap();
        map.put("requestMessage","{\n" +
                "\"Header\":{\n" +
                "\"MESSAGENAME\":\"MES.CREATELOT\",\n" +
                "\"TRANSACTIONID\":\"20140807095523941368\",\n" +
                "\"ORGRRN\":\"378341\",\n" +
                "\"ORGNAME\":\"GZSL02\",\n" +
                "\"USERNAME\":\"EAP\"\n" +
                "},\n" +
                "\"Body\":{\n" +
                "\"ACTIONTYPE\":\"NORMAL\",\n" +
                "\"EQUIPMENTID\":\"2019091601\",\n" +
                "\"PORTID\":\"2019091601\",\n" +
                "\"DURABLEID\":\"94131703\",\n" +
                "\"STEPNAME\":\"111\",\n" +
                "\"MLOTID\":\"TEST-LCL-9941729\",\n" +
                "\"COMPONENTLIST\":[\n" +
                "{\n" +
                "\"COMPONENTID\":\"TEST-L-9412\",\n" +
                "\"POSITION\":\"1\"\n" +
                "}\n" +
                "]\n" +
                "}\n" +
                "}");


        map.put("senderId","MaxwellSender");
        map.put("timeOut",3000);
        map.put("transactionId","20140807095523941368");
        String str= OkHttpUtil.postMap("http://192.168.8.9:8080/esb/RestService/postrequest",map);
        System.out.println("str----------------"+str);
    }
    public static void main(String[] args) {
        MesService ms=new MesService();
        ms.unloadRequest();
    }
}
